import http from '@/utils/http'

const BASE_URL = '/system/employee'

export type EmployeeType = 'LEAD_TEACHER' | 'ASSIST_TEACHER' | 'SELLER'

export interface EmployeeResp {
  id: string
  username: string
  name: string
  avatar: string
  gender: number
  email: string
  mobilePhone: string
  status: 0 | 1
  orgId: string
  orgName: string
  lastLoginIp: string
  lastLoginTime: string
  lastPwdModifiedTime: string
  type: string
}

export interface EmployeeDetailResp extends EmployeeResp {
  roleIdList: string[]
  roleList: any[]
}

export interface EmployeeQuery extends SortQuery {
  keyword?: string
  status?: number
  orgId?: string
  type?: EmployeeType
  includeSingleOrg?: boolean
}

export interface EmployeePageQuery extends EmployeeQuery, PageQuery {

}

/** @desc 分页查询员工列表 */
export function getPage(query: EmployeePageQuery) {
  return http.get<Page<EmployeeResp[]>>(`${BASE_URL}/page`, query)
}

/** @desc 查询员工列表 */
export function getList(query: EmployeeQuery) {
  return http.get<EmployeeResp[]>(`${BASE_URL}/list`, query)
}

/** @desc 查询员工详情 */
export function getDetail(id: string) {
  return http.get<EmployeeDetailResp>(`${BASE_URL}/detail/${id}`)
}

/** @desc 新增员工 */
export function create(data: any) {
  return http.post(`${BASE_URL}/create`, data)
}

/** @desc 修改员工 */
export function update(data: any, id: string) {
  return http.post(`${BASE_URL}/update/${id}`, data)
}

/** @desc 删除员工 */
export function remove(id: string) {
  return http.post(`${BASE_URL}/delete/${id}`)
}

/** @desc 禁用员工 */
export function changeStatus(id: string, status: number) {
  return http.get(`${BASE_URL}/change-status?id=${id}&status=${status}`)
}

/** @desc 修改密码 */
export function resetPassword(data: any) {
  return http.post(`${BASE_URL}/resetPassword`, data)
}

/** @desc 修改组织 */
export function changeOrg(data: any) {
  return http.post(`${BASE_URL}/changeOrg`, data)
}
